package map.coreui.fragment

import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import com.baidu.mapapi.navi.BaiduMapNavigation
import com.baidu.mapapi.search.route.WalkingRouteLine
import com.zjw.zy.R
import com.zjw.zy.ext.go
import com.zjw.zy.ext.longToast
import map.coreui.view.BackView
import map.coreui.view.MultiRouteView
import map.viewmodel.MultiRouteViewModel
import map.viewmodel.RoutePlanViewModel

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/10/24 15:23
 * @description：
 */
class MultiRouteFragment : MapBaseFragment() {

    private val routePlanViewModel: RoutePlanViewModel by activityViewModels()
    private val multiRouteViewModel: MultiRouteViewModel by viewModels()

    private val mainRoute: MultiRouteView by lazy { findViewById(R.id.multi_route_fragment_main) }
    private val backView: BackView by lazy { findViewById(R.id.multi_route_back) }

    override fun onPageEnter() {
        multiRouteViewModel.onPageEnter()
    }

    override fun onViewRestore(savedInstanceState: Bundle?) {

    }

    override fun onSubscribe() {
        //步行导航，绘制路线
        routePlanViewModel.getRouteWalkResult().observe(this) {
            routePlanViewModel.drawPath(it[0])
            mainRoute.bindData(it)
        }
    }

    override fun onBindViewListener() {
        mainRoute.bindListener(object : MultiRouteView.RouteSelectListener {
            override fun onSelectRoute(route: WalkingRouteLine) {
                routePlanViewModel.drawPath(route)
            }

            override fun onNavi() {
                //打开地图app
                 routePlanViewModel.openMapNavi()
            }
        })

        backView.attachTo(this)
    }

    override fun onBindViewValue() {

    }

    override fun onFindView(rootView: View?) {

    }

    override fun onLayoutId(): Int {
        return R.layout.multi_route_fragment
    }

    override fun onPageExit() {
        multiRouteViewModel.onPageExit()
    }
}